<template>
  <el-dialog
    class="base-dialog"
    :title="title"
    :visible.sync="isShowDialog"
    :append-to-body="true"
    :before-close="handleCloseDialog"
    custom-class="panna-dialog_medium customerDetectionItemAdd"
    @closed="closedDialog"
  >
    <el-form ref="filterForm" inline>
      <el-form-item :label="customer.itemName" prop="detectionItemName">
        <el-input
          v-model="filterForm.detectionItemName"
          :placeholder="customer.itemName"
          clearable
          @keyup.enter.native="getList('filter')"
        />
      </el-form-item>
      <el-form-item class="base-filter-button">
        <el-button
          v-loading="searchLoading"
          type="primary"
          @click="getList('filter')"
          >{{ operateType.query }}</el-button
        >
        <el-button @click="cancelForm">{{ operateType.clear }}</el-button>
      </el-form-item>
    </el-form>

    <div class="basic-info">
      <el-table
        ref="CustomerDetectionItemPrice"
        style="overflow: scroll; height: 100%"
        :data="dataList"
        element-loading-text="Loading"
        fit
        highlight-current-row
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column align="center" :label="customer.serialNumber" width="50">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>

        <el-table-column prop="detectionItemName" :label="customer.itemName">
        </el-table-column>
        <el-table-column prop="agreementPrice" :label="customer.unitPrice">
          <template slot-scope="scope">
            {{ scope.row.agreementPrice / 100 }}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <span slot="footer" class="base-dialog-footer">
      <el-button type="primary" @click="submit">{{ operateType.save }}</el-button>
      <el-button @click="handleCloseDialog">{{ operateType.cancel }}</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { GetSysBusinessDetectionItemGroupByNameList } from "../../../api/DetectionItemManage/SysBusinessDetectionItem";
import { creates } from "../../../api/SysBusiness/CustomerDetectionItemPrice";

export default {
  name: "CustomerDetectionItemAdd",
  components: {},
  props: {
    editId: {
      type: [String, Number],
      default: "",
    },
    isShowDialog: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      multipleSelection: [],
      total: 0,
      pageInfo: {
        pageIndex: 1,
        pageSize: 10,
      },
      dataList: [],
      title: this.$t("Customer.testingProjectQuotation"),
      filterForm: {
        detectionItemName: "",
      },
    };
  },
  computed: {
    operateType() {
      return this.$t("ModuleSysBusiness.OperateType") || {};
    },
    customer() {
      return this.$t("Customer") || {};
    },
  },

  mounted() {},
  created() {
    this.getList();
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    submit() {
      var obj = {};
      obj.customerId = this.editId;
      obj.detectionItemArray = this.multipleSelection;
      creates(obj)
        .then((res) => {
          this.$emit("update:isShowDialog", false);
          this.$emit("initdata", false);
        })
        .catch((res) => {
          this.$emit("update:isShowDialog", false);
          this.$emit("initdata", false);
        });
    },
    cancelForm() {
      this.filterForm.detectionItemName = ''
      this.getList("filter");
    },

    getList() {
      GetSysBusinessDetectionItemGroupByNameList(this.filterForm)
        .then((res) => {
          this.dataList = res.data;
        })
        .catch((res) => {});
    },
    handleClick() {},

    // 关闭弹框
    handleClose() {
      // 动画结束后在清空表单 防止页面闪烁
      this.$emit("update:isShowDialog", false);
    },
    // 关闭客户弹框没保存
    handleCloseDialog() {
      // 动画结束后在清空表单 防止页面闪烁
      this.$emit("update:isShowDialog", false);
    },
    // 关闭弹框动画结束
    closedDialog() {
      // 动画结束后在清空表单 防止页面闪烁
    },
    handleCloseChildDialog() {
      this.$refs["ruleForm"].resetFields();
      this.isShowChildDialog = false;
    },
    closedChildDialog() {
      this.$refs["ruleForm"].resetFields();
      this.isShowChildDialog = false;
    },
  },
};
</script>
<style scoped>
.customerDetectionItemAdd.base-dialog.el-dialog__body {
  overflow: none !important;
}
</style>
